﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HTTT.DataAccess;
using HTTT.Bussiness;
using HTTT.Utilities;

namespace HTTT.admin
{
    public partial class ResetUser : System.Web.UI.Page
    {
        /// <summary>
        ///  View State EditItemID
        /// </summary>
        private string Username
        {
            get
            {
                object obj = this.ViewState["_Username"];
                if (obj == null)
                    return null; //default to show ID : 0 
                else
                    return (string)obj;
            }
            set
            {
                this.ViewState["_Username"] = value;
            }

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadForm();
            }
        }


        private void LoadForm()
        {
            Username = Request.QueryString["Username"].ToString();
            if (Username != string.Empty)
            {
                //Add user detail
                ucUserDetail1.UserName = Username;
                ucUserDetail1.IsReadOnly = true;
            }
        }

        private ReturnValue<bool> ValidateData()
        {
            if (txtFromRequest.Text.Trim() == string.Empty) return new ReturnValue<bool>(false, "Phải nhập thông tin yêu cầu");
            return new ReturnValue<bool>(true, "");
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            ReturnValue<bool> Valid = ValidateData();
            if (Valid.RetValue)
            {
                HT_UserBO bo = new HT_UserBO();
                bool result = bo.ResetPwdUser(Username, Page.User.Identity.Name, txtFromRequest.Text);
                if (result)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "Message", Common.FormatMsgThenRedirect("Tạo yêu cầu đặt lại mật khẩu thành công !", "UserList.aspx"), true);
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "Message", Common.FormatAlertMsg(Valid.Msg), true);
            }
            
        }
        protected void btnCancel_Click(Object sender, EventArgs e)
        {
            Response.Redirect("UserList.aspx");
        }
    }
}